package org.shuma.goods.config;

import org.shuma.goods.interceptor.AuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author : liuming
 * @date : 2024/6/19 上午8:56
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        // 项目中的所有接口都支持跨域
        registry.addMapping("/**")
                //允许哪些域能访问我们的跨域资源
                .allowedOrigins("*")
                //允许的访问方法"POST", "GET", "PUT", "OPTIONS", "DELETE"等
                .allowedMethods("*")
                //允许所有的请求header访问，可以自定义设置任意请求头信息
                .allowedHeaders("*");
    }

    @Autowired
    private AuthInterceptor authInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/login","/registry","/code");
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
